<?php

App::uses('CompositeKeyModel', 'Model');

/**
 * OrganisationSetting Model
 *
 * @property Organisation $Organisation
 * @property MemberCategorySetting $MemberCategorySetting
 */
class OrganisationMemberCategorySetting extends CompositeKeyModel {
    //The Associations below have been created with all possible keys, those that are not needed can be removed

    public $useDbConfig = "organisations";
    public $primaryKeys = array('id', 'organisation_id');
    
    /**
     * belongsTo associations
     *
     * @var array
     */
    public $belongsTo = array(
        'Organisation' => array(
            'className' => 'Organisation',
            'foreignKey' => 'organisation_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'OrganisationMemberCategory' => array(
            'className' => 'OrganisationMemberCategory',
            'foreignKey' => 'organisation_member_category_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'MemberCategorySetting' => array(
            'className' => 'MemberCategorySetting',
            'foreignKey' => 'member_category_setting_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

    public function getSetting($organisation_id, $organisation_member_category_id, $setting_key) {
        return $this->find('first', array(
            'conditions' => array(
                'OrganisationMemberCategorySetting.organisation_id' => $organisation_id,
                'OrganisationMemberCategorySetting.organisation_member_category_id' => $organisation_member_category_id,
                'MemberCategorySetting.name' => $setting_key
            )
        ));
    }
}
